//
//  HCoreConfig.h
//  HMusicPlayer
//
//  Created by Hament on 14/9/5.
//  Copyright (c) 2014年 HJ. All rights reserved.
//



#pragma mark /*--------------------------------通用配置-----------------------------*/
/*----------路径相关-------------*/
#define HDocumentDirectory  [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
#define HLibraryDirectory   [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0]
#define HCachesDirectory    [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0] //这个不会被itunes备份
#define HTempDirectory      NSTemporaryDirectory()

#define HMusicDirectory   [NSSearchPathForDirectoriesInDomains(NSMusicDirectory, NSUserDomainMask, YES) objectAtIndex:0]//music

#define versionInfoPath   [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/versionInfo.plist"]//app版本信息

//app内的路径,文件,文件夹
#define skinConfigKey      @"skinConfig" //skin配置名字,skinConfig.plist
#define skinFolder         [HDocumentDirectory stringByAppendingPathComponent:@"skin"]//skin folder
#define skinConfigFolder   [HDocumentDirectory stringByAppendingPathComponent:@"skin/currentskin"]//currents skin folder
#define skinConfigPath     [HDocumentDirectory stringByAppendingPathComponent:@"skin/currentskin/skinConfig.plist"]//更新信息

#define tempLyricPath      [HCachesDirectory stringByAppendingPathComponent:@"tempLyric.lrc"] //临时歌词路径

//网上下载资源存放的文件夹
#define musicCache  [HCachesDirectory stringByAppendingPathComponent:@"music"]
#define lyricsCache [HCachesDirectory stringByAppendingPathComponent:@"lyrics"]
#define albumCache  [HCachesDirectory stringByAppendingPathComponent:@"album"]

//歌曲数据库
#define songDBPath  [HCachesDirectory stringByAppendingPathComponent:@"song.db"]



/*
 userdefault
 */

/*设置userdefaults里面某key的值 */
#define SetUserDefaultsForKey(key,value)   [[NSUserDefaults standardUserDefaults] setObject:value forKey:key]
/*获取userdefaults里面某key的值*/
#define GetUserDefaultsWithKey(key)  [[NSUserDefaults standardUserDefaults] objectForKey:key]

//userdefault key
#define  UseLanguage				@"UseLanguage" //使用语言
//#define  IsImportItunesPlaylist		@"IsImportItunesPlaylist" //是否导入itunes 播放列表 bool


#define  RemoveItunesAsk            @"removeItunesAsk"//删除itunes的歌曲是否需要询问
#define  AutoDownloadLyrics         @"autoDownloadLyrics"//是否自动下载歌词
#define  LyricsFontSize             @"lyricsFontSize"//歌词非全屏时的font size
#define  LyricsFullScreenFontSize   @"lyricsFullScreenFontSize"//歌词全屏时的font size

#define  HSongSortType              @"HSongSortType" //歌曲排序类型
#define  SortByName                 @"SortByName"
#define  SortByDate                 @"SortByDate" //或者基本可以按ID排序/ trackID

//最近一次播放的信息
#define  HCurrentPlayInfo           @"HCurrentPlayInfo"//最近一次播放的信息 dic
#define  HVolume                    @"HVolume" 
#define  HPlayMode                  @"HPlayMode"  // 1 :顺序  2:循环  3:随机 4.单曲循环
#define  HPlaylistID                @"HPlaylistID" // 当前播放列表ID
#define  HPlaySongPath              @"HPlaySongpath" // 当前播放歌曲路径

//获取专辑封面key
#define HArtwork   @"artwork"


/*
 获取Mainbundle 里面文件路径
 */
#define fileBundlePath(file,extention) [[NSBundle mainBundle]pathForResource:file ofType:extention]


/*用于上传的参数key*/
#define PostKey					@"Key"
#define PostStringValue			@"Value"
#define PostData				@"DataValue"



/*
 ----------字符串--------
 */


/*检查字串*/
#define CHECKSTR(str) (str == nil || [str isKindOfClass:[NSNull class]])? @"" : str

//检查日期格式字串
#define  InitlizSyncTimeStamp @"0000-00-00 00:00:00"
#define CHECKDateSTR(str) (str == nil || [str isKindOfClass:[NSNull class]])? InitlizSyncTimeStamp : str


//本地化字符串
#define localString(A) NSLocalizedString(A,nil)

//-------------颜色----------------


#define RGBA(r,g,b,a) [NSColor colorWithCalibratedRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]//a为0~1



//-------------api相关-----------
#define APIDomain               @"http://www.baidu.com" //domain

//---获取歌词的api
//歌词迷
#define GECIMIAPISERVER         @"http://www.geci.me/api/lyric" //http://geci.me/api/lyric/海阔天空/beyond
//b的webserver
#define BAPIWEBSERVER           @"http://box.zhangmen.baidu.com/x?op=12&count=1"//http://box.zhangmen.baidu.com/x?op=12&count=1&title=大约在冬季$$齐秦$$$$

/*
 App store
 */

#define TheAppID         @"XXXXXXX"
#define appBundleID      @"com.XXX.app"
#define appItunesInfo    @"http://itunes.apple.com/en/lookup?bundleId="//拼接bundleID
#define itunesAppLink    @"https://itunes.apple.com/cn/app/hi-ao-men/idXXXXXXXXX?mt=8" //xxx为appID






#pragma mark /*--------------------------------MAC配置-----------------------------*/

#define macBundleImage(file,extention) [[NSImage alloc] initWithContentsOfFile:fileBundlePath(file,extention)]


//----------frame size--------
#define hwindowHeigh  28        //title bar heigh
#define mainWindowMaxWidth  400  // main window max/min limit width (non fullscreen)
#define playPlaneHeigh  160     //play plane limit heigh
#define headerViewHeigh  30     //header limit heigh
#define playListViewWidth 150   // left playlist limit width


//plane view subview frame

#define SongTitleFrame     NSMakeRect(132, 135, 236, 19)
#define DurationViewFrame  NSMakeRect(134, 115, 260, 20) //slider + time
#define SoundViewFrame     NSMakeRect(368, 0, 32, 114)
#define LyricsViewFrame    NSMakeRect(134, 39, 232, 75)
#define ControlViewFrame   NSMakeRect(134, 4, 232, 32)
#define ShareBtnFrame      NSMakeRect(369, 139, 20, 18)

//全局reminder的heigh和width
#define HReminderHeigh   50
#define HReminderWidth   300

//----------tag--------
#define playTringleViewTag 999999999
#define InvalidSoundDuration  99999999

//import menu tag
#define importPlistTag      100
#define importASPlistTag    101
#define importItunesTag     102


//sort menu tag
#define sortNameTag      100
#define sortDateTag      101



//----------special key--------

//播放列表上特殊的分组标识符
#define itunesSyncid @"itunesSyncid" //itunes
#define onlineSyncid @"onlineSyncid" //online music
#define likeSyncid   @"likeSyncid"   //收藏
#define tempSyncid   @"tempSyncid"   //temp

//UTI Type
#define HSONGITEMTYPE  @"hj.gladMusic.songitem" //HSongItem
#define HSONGIDATATYPE @"hj.gladMusic.songData" //HSongdata 



//播放器种类
typedef enum : NSInteger {
    ORGMEngineType=1,
    DOUAudioType
} HAudioPlayerType;



#import <Foundation/Foundation.h>

@class  HskinManager,HSongItem,iTunesFileTrack;

@interface HCoreConfig : NSObject

@property (nonatomic,strong) NSString * currentAppVersion;//app版本号
@property (nonatomic,strong) NSDateFormatter * defaultdateFormater;
@property (nonatomic,strong) HskinManager * currentSkinManager;
//@property (nonatomic) BOOL isImportItunesPl;//是否导入itunes 播放列表
@property (nonatomic,strong) NSString * musicDocumentPath;

@property (nonatomic,strong) HSongItem * currentDownloadItemj;

//一些设置&开关
@property (nonatomic) BOOL removeItunesAsk;//删除itunes的歌曲是否需要询问
@property (nonatomic) BOOL autoDownloadLyrics;//是否自动下载歌词
@property (nonatomic) NSUInteger  lyricsFontSize;
@property (nonatomic) NSUInteger  lyricsFullScreenFontSize;
@property (nonatomic,strong) NSString * currentSortType;//歌曲排序方式

@property (nonatomic,strong) NSMutableDictionary  * currentPlayInfo;//保存最近一次歌曲播放信息

//-------全局调用的图片-----
//删除歌曲
@property (nonatomic,strong) NSImage * delSongNorImg;
@property (nonatomic,strong) NSImage * delSongHltImg;

//like song
@property (nonatomic,strong) NSImage * likeSongImg;
@property (nonatomic,strong) NSImage * unlikeSongImg;

//添加playlist
@property (nonatomic,strong) NSImage * addPlaylistNorImg;
@property (nonatomic,strong) NSImage * addPlaylistHltImg;

@property (nonatomic,strong) NSMutableArray * holdWindoControllerArr;//持有wc的数组

@property (nonatomic) BOOL isPro;//pro or lite 

#pragma mark singleon
+(HCoreConfig *)shareConfig;

- (NSString *) getUserLang;//获取语言

//根据版本更新数据库
-(BOOL)isNeedUpdateDB;

//刷新使用的全局图片
-(void)refreshSkinImage;

//保存当前播放信息
-(void)savePlayInfo;

#pragma mark /*----------------字符串处理-------------*/
//字符串替换
+(NSString *) ReplaceFirstNewLine:(NSString * )original symbol:(NSString*)symbol replaceWith:(NSString*)replaceStr;
//快速去除html<> 标记
+(NSString *) stringByStrippingHTML:(NSString*)htmlstr;

//milesecond To MM:SS
+(NSString* )convertMileSecond:(NSUInteger)duration;

#pragma mark /*----------------数据类型转换处理-------------*/
#pragma mark number To String
+(NSString*)numberToString:(id)numvalue;

#pragma mark /*----------------其他-------------*/
+(NSString*)generateMD5Hash;//MD5
+(NSString*)generateSyncID;//毫秒


#pragma mark /*----------------业务逻辑-------------*/
//获取sound property,这里只获取时长
-(NSUInteger)getSoundDuration:(NSURL*)audioURL;

#pragma mark 获取aac/m4a 图片
+(void)getSoundPropertyWithPath:(NSString*)path completion:(void (^)(NSDictionary*))completion;
#pragma mark------写入aac/m4a tag信息
+(void)writeSongInnerArtWorkWithPath:(NSString*)path image:(NSImage*)image;

//检测是否无损歌曲
+(BOOL)checkLosslessWithSongItem:(HSongItem*)songitem;

#pragma mark itunes
//获取iunes 所有歌曲
-(NSMutableArray*)getItunesSongs;

//获取iunes 我最喜爱的歌曲列表
-(NSMutableArray*)getItunesFavouriteSongs;

//删除iunes歌曲
+(void)deleteItunesSongsWithSongitems:(NSArray*)songItems;

//like/unlike iunes歌曲
+(void)likeItunesSongWithSongitem:(HSongItem*)songItem;

//对itunes的歌曲进行编辑,分启动和未启动
+(void)editItunesNameSongWithSongitem:(HSongItem*)songItem andNewname:(NSString * )theNewName;

//使用路径判断歌曲是否来自itunes library
+(BOOL)checkSongisBelongToItunesWithPath:(NSString*)path;



//根据路径找出itunesfiletack
+(iTunesFileTrack*)getItunesFiletrackWithPath:(NSString*)path;

+(void)testItunes;



//根据歌曲路径生成songitems ,playlistType: favourite=1
+(NSArray*)getSongItemsWithAudiopaths:(NSArray*)paths type:(NSUInteger)playlistType;


//导入歌曲到itunes的tracks
+(BOOL)importSongToItunesWithpath:(id)path;

//itunes update
+(void)updateItunes;


#pragma mark 打开/关闭AccessingSecurityScoped----
+(BOOL)openFilesAccessingSecurityScopedWithSongItem:(HSongItem*)songItem;
+(void)stopFilesAccessingSecurityScopedWithSongItem:(HSongItem*)songItem;

#pragma mark -----控件处理----

// 弹出警告框
+(void)alertWithTitle:(NSString*)title window:(NSWindow*)window;

//设置NSButton normal /helighted 颜色
+(void)configButton:(NSButton*)button Title:(NSString *)title normalColor:(NSColor*)normalColor helightedColor:(NSColor*)helightedColor  shadow:(NSShadow*)shadow;

//设置nsmenuitem title color
+(void)configMsnuItem:(NSMenuItem*)menuItem Title:(NSString *)title normalColor:(NSColor*)normalColor shadow:(NSShadow*)shadow;

//为NSbutton设置menu
+(void)setButton:(NSButton*)button menu:(NSMenu*)themenu offset:(NSPoint)point;


//导出
+(void)saveWithWindow:(NSWindow*)window panel:(NSOpenPanel*)panel completionHandler:(void(^)(NSInteger result))handel;


//cmyk to rgba
+(NSString*)rgbaColorValueWithCmykColor:(NSColor*)cmykColor;


// complement color of  rgba 互补色
+(NSString*)complementaryColorrgbaColor:(NSString*)rgbas;

// 获取处理过颜色的图片,name不带exention,必须是png,能处理alpha
-(NSImage*)getImageWithMainBundle:(NSString*)name;
-(NSImage*)getImageWithMainBundle:(NSString*)name configDic:(NSDictionary*)configDic;
+(NSImage *)imageResize:(NSImage*)anImage newSize:(NSSize)newSize;//图片缩放
//返回img data
+(NSData*)imageConvertData:(NSImage*)sourceImage  imageFileType:(NSBitmapImageFileType)imagetype fitDeviceScale:(BOOL)flag;


#pragma mark窗口截图
+(NSImage*)windowImageShot:(NSWindow*)window;


@end
